using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using MobileClient.UIProcessService;

namespace MobileClient
{
	/// <summary>
	/// Summary description for ctlMultiSelectEntry.
	/// </summary>
	public class ctlMultiSelectEntry : Control
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.ListView lstSelections;
		private System.Windows.Forms.ColumnHeader chdrSelection;

		private MultiSelectEntry m_objEntry;

		public ctlMultiSelectEntry()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			m_objEntry = null;
		}

		public MultiSelectEntry Entry
		{
			get { return m_objEntry; }
			set { m_objEntry = value; }
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if( components != null )
					components.Dispose();
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.lstSelections = new System.Windows.Forms.ListView();
			this.chdrSelection = new System.Windows.Forms.ColumnHeader();
			// 
			// lstSelections
			// 
			this.lstSelections.CheckBoxes = true;
			this.lstSelections.Columns.Add(this.chdrSelection);
			this.lstSelections.FullRowSelect = true;
			this.lstSelections.Location = new System.Drawing.Point(3, 6);
			this.lstSelections.Size = new System.Drawing.Size(230, 140);
			this.lstSelections.View = System.Windows.Forms.View.Details;
			// 
			// chdrSelection
			// 
			this.chdrSelection.Text = "Items";
			this.chdrSelection.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.chdrSelection.Width = 215;
			// 
			// ctlMultiSelectEntry
			// 
			this.Controls.Add(this.lstSelections);
			this.Size = new System.Drawing.Size(236, 152);

		}
		#endregion

		public void LoadSettings()
		{
			if(m_objEntry != null)
			{
				ListViewItem lvItem;

				lstSelections.Items.Clear();

				if(m_objEntry.Options != null)
				{
					foreach(String strItem in m_objEntry.Options)
					{
						lvItem = new ListViewItem(strItem);
						lstSelections.Items.Add(lvItem);
					}
				}
			}
		}

		public void SaveSettings()
		{
			if(m_objEntry != null)
			{
                string arrSelected = "";
				foreach(ListViewItem lvItem in lstSelections.Items)
				{
					if(lvItem.Checked)
					{
                        arrSelected += lvItem.Text + ",";
					}
				}

				m_objEntry.Selections = arrSelected.Split(',');
			}
		}
	}
}
